package cn.gy.productservice.service;

import cn.gy.productservice.SerciceException.ProductException;
import cn.gy.common.model.Product;
import cn.gy.productservice.mapper.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductService {

    @Autowired
    private ProductMapper productMapper;

    public Product findByProductId(Long productId) {
        Product product = productMapper.findByProductId(productId);
        if (product == null) {
            throw new ProductException("Product not found with id: " + productId);
        }
        return product;
    }

    public Product findByProductName(String nm) {
        Product product = productMapper.findByProductName(nm);
        if (product == null) {
            throw new ProductException("Product not found with name: " + nm);
        }
        return product;
    }

    public List<Product> queryAllProduct() {
        List<Product> productList = productMapper.queryAllProduct();
        if (productList == null) {
            throw new ProductException("qProduct not found");
        }
        return productList;
    }
}
